// EnRecentFileList.cpp: implementation of the CEnRecentFileList class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "EnRecentFileList.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CEnRecentFileList::CEnRecentFileList(UINT nStart, LPCTSTR lpszSection,
	    LPCTSTR lpszEntryFormat, int nSize, int nMaxDispLen, LPCTSTR szOriginal) 
       : CRecentFileList(nStart, lpszSection, lpszEntryFormat, nSize, nMaxDispLen) 
{
   m_strOriginal = szOriginal;
}

CEnRecentFileList::~CEnRecentFileList()
{

}

void CEnRecentFileList::UpdateMenu(CCmdUI* pCmdUI)
{
    if (m_arrNames[0].IsEmpty())
	{
	   if (pCmdUI->m_pMenu == NULL)
		   return;

      // delete all but the first item
	   for (int iMRU = 1; iMRU < m_nSize; iMRU++)
		   pCmdUI->m_pMenu->DeleteMenu(pCmdUI->m_nID + iMRU, MF_BYCOMMAND);
	}

   CRecentFileList::UpdateMenu(pCmdUI);
}

void CEnRecentFileList::RemoveAll(BOOL bClearProfile)
{
	int nItem = GetSize();

	while (nItem--)
		Remove(nItem);

	if (bClearProfile)
		CRecentFileList::WriteList();
}

void CEnRecentFileList::WriteList(CPreferences& prefs) const
{
	for (int nFile = 0; nFile < GetSize(); nFile++)
	{
		if (m_arrNames[nFile].IsEmpty())
			break;
		
		CString sItem;
		sItem.Format(m_strEntryFormat, nFile + 1);
		prefs.WriteProfileString("MRU", sItem, m_arrNames[nFile]);
	}
}

void CEnRecentFileList::ReadList(const CPreferences& prefs)
{
	for (int nFile = 0; nFile < GetSize(); nFile++)
	{
		CString sItem;
		sItem.Format(m_strEntryFormat, nFile + 1);
		m_arrNames[nFile] = prefs.GetProfileString("MRU", sItem);
	}
}
